#include "TextView.h"

#include "../PLATFORM.h"
#ifdef _ANDROID_PLATFORM__
#include "SDL_ttf.h"
#else
#include <SDL2/SDL_ttf.h>
#endif

#include "../_Luly.h"
#include "Layout.h"
#include "_Font.h"
#include "_UI.h"

TextView::TextView(std::string uiObjectId, std::string text, int x, int y)
    : UIObject(uiObjectId, x, y, 0, 0), textAdapt(true) {
  font = _UI::getInstance().getDefaultFont();
  TextView::text = Text(text, font);
}

void TextView::init() {
  TextView::text.init();
  UIObject::init();
}

void TextView::event() { UIObject::event(); }

void TextView::update() { UIObject::update(); }

void TextView::draw() {
  // text.draw(font, color, x, y, scale, angle);
  // width = text.getWidth();
  // height = text.getHeight();
  // UIObject::draw();
  drawArea(Rect{contentX, contentY, contentWidth, contentHeight});
}

void TextView::drawArea(const Rect& area) {
  TextView::area = area;
  text.drawArea(area, font, color, x, y, scale, angle);
  width = text.getWidth();
  height = text.getHeight();
}